package com.dc.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dc.common.core.PageParamDto;
import com.dc.common.vo.PageResultVo;

/**
 * @author zhuangcy
 * @date 2021/1/16
 * @description 分页工具类
 */
public class PageUtil {
    /**
     * @author zhuangcy
     * @date 2021/1/16
     * @description 转换为自定义PageResult
     */
    public static <T> PageResultVo<T> convert2PageResult(IPage<T> page) {
        PageResultVo<T> result = new PageResultVo();
        result.setPageNum(page.getCurrent());
        result.setPageSize(page.getSize());
        result.setTotal(page.getTotal());
        result.setList(page.getRecords());
        return result;
    }

    /**
     * 转换为自定义Page参数
     *
     * @param param
     * @return
     */
    public static IPage convert2PageParam(PageParamDto param) {
        Page page = new Page<>();
        page.setCurrent(param.getPageNum());
        page.setSize(param.getPageSize());
        return page;
    }
}
